package com.xfb.user.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.SQLException;

@Configuration
public class DataSourceConfig {

    @Value("${mysql.driverClassName}")
    String className;

    @Value("${mysql.url}")
    String mysqlUrl;

    @Value("${mysql.name}")
    String name;

    @Value("${mysql.password}")
    String password;

    @Autowired
    DataSourceProperties dataSourceProperties;

    @Bean
    public DataSource getDataSource() throws SQLException {
        DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName(className);
        dataSourceBuilder.url(mysqlUrl);
        dataSourceBuilder.username(name);
        dataSourceBuilder.password(password);
        DataSource build = dataSourceBuilder.build();
        return build;
    }

}
